import tensorflow as tf
import numpy as np

tf.compat.v1.disable_eager_execution()

#v1 = tf.constant([1,2,3,4,5])
#v2 = tf.constant([2,1,5,3,4])
#v_add = tf.add(v1,v2)
#sess = tf.compat.v1.Session()
#print(sess.run(v_add))

x = tf.Variable(0.)
y = tf.Variable(1.)
# x =  x + y
add_op = x.assign(x + y)
# y = y / 2
div_op = y.assign(y / 2)
with tf.compat.v1.Session() as sess2:  # 打开会话
    sess2.run(tf.compat.v1.global_variables_initializer()) # 初始会话
    for iteration in range(50):
        sess2.run(add_op)
        sess2.run(div_op)
    print(x.eval()) # x为variable对象，用eval函数调取真实值 或者：sess.eval(x)

